package com.dreamlin.basepro;

import android.content.Context;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.dreamlin.basepro.common.SecurityUtils;
import com.dreamlin.netty.NettyTcpClient;
import com.dreamlin.netty.message.EventListener;
import com.dreamlin.netty.message.IMsgConfig;
import com.dreamlin.netty.protocol.MessageProtocol;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();

        assertEquals("com.dreamlin.basepro", appContext.getPackageName());
    }

    @Test
    public void encrypt() throws Exception {
        String btrh201911PERMIS = SecurityUtils.encrypt("9150", "BTRH201911PERMIS");
        System.out.println(btrh201911PERMIS);
    }
    @Test
    public void runClient() {
        NettyTcpClient.getInstance().connectServer("192.168.4.222", 60001, "client001", new EventListener() {
            @Override
            public void onReceive(MessageProtocol message) {
                System.out.println("ChatActivity.onReceive:" + message.toString());
            }

            @Override
            public void onSendSuccess(MessageProtocol message) {
                System.out.println("ChatActivity.onSendSuccess:" + message.getHead().getSerialId());
            }

            @Override
            public void onSendFailed(MessageProtocol message) {
                System.out.println("ChatActivity.onSendFailed:" + message.getHead().getSerialId());
            }

            @Override
            public void onConnected(int state) {
                if (state == IMsgConfig.CONNECTED_SUCCESS) {
                    System.out.println("ChatActivity.onConnected 连接成功");
                } else if (state == IMsgConfig.CONNECTED_FAILED) {
                    System.out.println("ChatActivity.onConnected 连接失败");
                }
            }

            @Override
            public void onDisconnected() {
                System.out.println("ChatActivity.onDisconnected");
            }

            @Override
            public boolean isNetworkAvailable() {
                return true;
            }
        });
    }

}
